<?php

use Illuminate\Database\Seeder;
use Faker\Factory;
use App\Model\Admin\Tag;

class TagTableSeeder extends Seeder
{
    /**
     * php artisan make:seeder TagTableSeeder
     *
     * php artisan db:seed --class=TagTableSeeder
     *
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
       initCliEnv();

       DB::table('tag')->truncate();

        $i = 1;
        $faker = Factory::create();

        while ($i < 10 && count(Tag::all()) < 9) {
            $name = $faker->firstName;

            $exist = Tag::where('name', $name)->first();

            if (!$exist) {
                $r = Tag::create([
                    'name' => $name,
                    'user_id' => $i,
                    'is_active' => rand(0, 1),
                ]);
                if ($r->wasRecentlyCreated) {
                    $i++;
                }
            }
        };
    }

    public function data()
    {
        return [];
    }
}
